

import 'package:flutter/material.dart';

class HeroLogoSliverAppbar extends StatelessWidget {
  double expandedHeight;
  Widget appbarContent;
  String title;
  bool pinned;
  bool useSearchBar;
  void Function(String text) searchHandler = (String text){};

  HeroLogoSliverAppbar({this.title, this.appbarContent, this.pinned, this.expandedHeight, this.useSearchBar = false, this.searchHandler});

  @override
  Widget build(BuildContext context) {
    return SliverAppBar(
      centerTitle: true,
      pinned: pinned,
      expandedHeight: expandedHeight,
      flexibleSpace: FlexibleSpaceBar(
      title: useSearchBar ? makeSearchBar() : Text(title),
      centerTitle: true,
      background: Stack(
        children: <Widget>[
          appbarContent,
          useSearchBar ?
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(top: 13.0),
                child: Text(title, style: TextStyle(
                  fontSize: 21.0,
                  color: Colors.white
                ),),
              )
            ],
          )
              :
          SizedBox()
        ],
      )
      ),
    );
  }

  Widget makeSearchBar(){
    return Container(
      width: 180.0,
//      color: Colors.green,
      child: TextField(
        style: TextStyle(
          fontFamily: "ukij-cjk",
          fontSize: 12.0
        ),
        decoration: InputDecoration(
          filled: true,
          fillColor: Colors.white30,
            contentPadding: EdgeInsets.symmetric(vertical: 5.0),
            enabledBorder: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(8.0)),
                borderSide: BorderSide(color: Colors.transparent)
            ),
            border: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(8.0)),
                borderSide: BorderSide(color: Colors.transparent)
            ),
            focusedBorder: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(8.0)),
                borderSide: BorderSide(color: Colors.white30)
            ),
            hintText: "ئىزدىمەكچى بولغان مەزمۇننى كىرگۈزۈڭ",
          hintStyle: TextStyle(
            color: Colors.white30,
            fontSize: 11.0,
          ),
        ),
        textAlign: TextAlign.center,
        onChanged: searchHandler ?? (text){},
      ),
    );
  }
}
